﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace CarbonExchange.WebControls
{
    [System.ComponentModel.Designer("System.Web.UI.Design.WebControls.PanelContainerDesigner, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
    [ParseChildren(false)]
    [PersistChildren(true)]
    public class RoundedBox : WebControl
    {
        public RoundedBox()
        {
            RoundedTop = true;
            RoundedBottom = true;
            this.Color = BoxColor.White;
        }

        public enum BoxColor
        {
            White,
            Charcol,
            Grey,
            Blue
        }

        public BoxColor Color { get; set; }
        public bool RoundedTop { get; set; }
        public bool RoundedBottom { get; set; }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            StringBuilder className = new StringBuilder();
            className.Append("roundedBox ");
            if(!string.IsNullOrEmpty(this.CssClass))
            {
                className.Append(this.CssClass.Trim());
                className.Append(" ");
            }
            switch (this.Color)
            {
                case BoxColor.White:
                    className.Append("whiteCnr ");
                    break;
                case BoxColor.Blue:
                    className.Append("blueCnr ");
                    break;
                case BoxColor.Charcol:
                    className.Append("charCnr ");
                    break;
                case BoxColor.Grey:
                    className.Append("greyCnr ");
                    break;
            }
            if(!RoundedTop)
                className.Append("noRoundT ");
            if(!RoundedBottom)
                className.Append("noRoundB ");

            writer.AddAttribute(HtmlTextWriterAttribute.Class, className.ToString().Trim());
                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "bl");
                    writer.RenderBeginTag(HtmlTextWriterTag.Div);

                        writer.AddAttribute(HtmlTextWriterAttribute.Class, "br");
                        writer.RenderBeginTag(HtmlTextWriterTag.Div);
    
                            writer.AddAttribute(HtmlTextWriterAttribute.Class, "tl");
                            writer.RenderBeginTag(HtmlTextWriterTag.Div);

                                writer.AddAttribute(HtmlTextWriterAttribute.Class, "tr");
                                writer.RenderBeginTag(HtmlTextWriterTag.Div);

                                    writer.AddAttribute(HtmlTextWriterAttribute.Class, "container clearfix");
                                    writer.RenderBeginTag(HtmlTextWriterTag.Div);
            
            RenderChildren(writer);
            
            
            writer.RenderEndTag();//container
            writer.RenderEndTag();//tr
            writer.RenderEndTag();//tl
            writer.RenderEndTag();//br
            writer.RenderEndTag();//bl
            writer.RenderEndTag();//wrapper

        }
    }
}
